package m202406.d11;

import java.util.Stack;

/**
 * @@author: 爱做梦的锤子
 * @date: 2024/6/11 17:15
 */
public class Q71 {
    public String simplifyPath(String path) {
        String[] split = path.split("/");
        Stack<String> stack = new Stack<>();
        for (String s : split) {
            if (".".equals(s) || s == null || s.trim().isEmpty()) {
                continue;
            }
            if ("..".equals(s)) {
                if (!stack.isEmpty()) {
                    stack.pop();
                }
                continue;
            }
            stack.push(s);
        }
        return "/" + String.join("/", stack);
    }
}
